package com.sunyzc.ebaotech.ybt.simulator.gzrcb;

import com.sunyzc.ebaotech.ybt.simulator.AbstractProcessor;

/**
 * 1021 - 新单试算(101) <br>
 * 1022 - 新单缴费(102) <br>
 * 1013 - 保单重打(103) <br>
 * 1002 - 当日悔单(201) <br>
 * 801 - 日结对账(801)(注意实际是没有对账请求的交易的) <br>
 */
public class GZRCBProcessor extends AbstractProcessor {
	private final static int HEAD_LENGTH = 16;
	private final static int BODY_LENGTH_BEGIN_INDEX = 8;
	private final static int BODY_LENGTH_END_INDEX = 16;
	private final static int SERVER_PORT = 8108;
	/** 由银行方发送和保险方返回的XML数据一律采用GBK编码方式 */
	private final static String TRANS_ENDCODING = "GBK";

	@Override
	public byte[] generateHeadBytes(String transType, byte[] bodyContent) throws Exception {
		String requestHeadContent = "INSU" + transType + String.format("%08d", bodyContent == null ? 0 : bodyContent.length); // INSU(4字节) + 交易码(4字节) + 包长(8 字节，左补0)
		return requestHeadContent.getBytes(TRANS_ENDCODING);
	}

	@Override
	public int getServerPort() {
		return SERVER_PORT;
	}

	@Override
	public String getTransEncoding() {
		return TRANS_ENDCODING;
	}

	@Override
	protected int getHeadLength() {
		return HEAD_LENGTH;
	}

	@Override
	protected int getBodyLengthBeginIndex() {
		return BODY_LENGTH_BEGIN_INDEX;
	}

	@Override
	protected int getBodyLengthEndIndex() {
		return BODY_LENGTH_END_INDEX;
	}
}
